package com.esri.android.map.ogc.kml;

import com.esri.android.map.Layer;
import com.esri.android.map.event.OnStatusChangedListener;
import com.esri.core.internal.map.KmlLayerInternal;
import com.esri.core.io.EsriSecurityException;
import com.esri.core.io.UserCredentials;
import com.esri.core.map.TimeAwareLayer;
import com.esri.core.map.TimeExtent;
import com.esri.core.map.TimeInfo;
import com.esri.core.map.ogc.kml.KmlNode;
import java.util.ArrayList;
import java.util.List;

/* loaded from: classes.dex */
public class KmlLayer extends Layer implements TimeAwareLayer {
    private static int c = 5;
    private KmlLayerInternal a;
    private TimeExtent b;
    private KmlNodeEventListener d;
    private boolean e;

    /* loaded from: classes.dex */
    public interface KmlNodeEventListener {
        void onNodeBeginRefresh(KmlNode kmlNode);

        void onNodeEndRefresh(KmlNode kmlNode);
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes.dex */
    public enum Event {
        END_NODE_AUTO_REFRESH("node_auto_refreshed"),
        BEGIN_NODE_AUTO_REFRESH("begin_node_auto_refresh");
        
        private String a;

        Event(String str) {
            this.a = str;
        }

        @Override // java.lang.Enum
        public String toString() {
            return this.a;
        }
    }

    public KmlLayer(String str) {
        this(str, null);
    }

    public KmlLayer(String str, UserCredentials userCredentials) {
        this.e = false;
        this.credentials = userCredentials;
        setUrl(str);
        initLayer();
    }

    public KmlNode[] getKmlNodes(double d, double d2, int i) {
        return getKmlNodes(d, d2, i, true);
    }

    public KmlNode[] getKmlNodes(double d, double d2, int i, boolean z) {
        try {
            ArrayList arrayList = new ArrayList();
            this.a.a(false);
            int a2 = this.a.a(d, d2, i, c);
            if (a2 > 0) {
                for (int i2 = 0; i2 < a2; i2++) {
                    KmlNode a3 = this.a.a(i2);
                    if (a3 != null) {
                        arrayList.add(a3);
                    }
                }
                if (z) {
                    this.a.a(true);
                }
            }
            return (KmlNode[]) arrayList.toArray(new KmlNode[0]);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public void setSelectedNode(KmlNode kmlNode, boolean z) {
        KmlLayerInternal kmlLayerInternal;
        if (kmlNode == null || (kmlLayerInternal = this.a) == null) {
            return;
        }
        kmlLayerInternal.a(kmlNode, z);
    }

    public void setSelectedNodes(KmlNode[] kmlNodeArr, boolean z) {
        if (kmlNodeArr == null || kmlNodeArr.length <= 0) {
            return;
        }
        for (KmlNode kmlNode : kmlNodeArr) {
            setSelectedNode(kmlNode, z);
        }
    }

    @Override // com.esri.android.map.Layer
    public void recycle() {
        super.recycle();
    }

    public void clearHighlightedNodes() {
        KmlLayerInternal kmlLayerInternal = this.a;
        if (kmlLayerInternal != null) {
            kmlLayerInternal.c();
        }
    }

    public List<KmlNode> getRootNodes() {
        ArrayList arrayList = new ArrayList();
        try {
            KmlLayerInternal kmlLayerInternal = this.a;
            if (kmlLayerInternal != null) {
                int b2 = kmlLayerInternal.b();
                for (int i = 0; i < b2; i++) {
                    arrayList.add(this.a.b(i));
                }
            }
            return arrayList;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override // com.esri.android.map.Layer
    protected long create() {
        if (this.a == null) {
            KmlLayerInternal kmlLayerInternal = new KmlLayerInternal(new b());
            this.a = kmlLayerInternal;
            kmlLayerInternal.a(new a());
        }
        return this.a.a();
    }

    /* JADX WARN: Code restructure failed: missing block: B:13:0x0033, code lost:
        if (r3.isFile() != false) goto L7;
     */
    /* JADX WARN: Removed duplicated region for block: B:26:0x0098  */
    /* JADX WARN: Removed duplicated region for block: B:29:0x003e A[EXC_TOP_SPLITTER, SYNTHETIC] */
    @Override // com.esri.android.map.Layer
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    protected void initLayer() {
        /*
            r6 = this;
            com.esri.core.internal.map.KmlLayerInternal r0 = r6.a
            if (r0 != 0) goto La
            long r0 = r6.create()
            r6.nativeHandle = r0
        La:
            java.lang.String r0 = r6.getUrl()
            r1 = 1
            r2 = 0
            if (r0 != 0) goto L14
        L12:
            r1 = 0
            goto L36
        L14:
            java.util.Locale r3 = java.util.Locale.ENGLISH
            java.lang.String r3 = r0.toLowerCase(r3)
            java.lang.String r4 = "http"
            boolean r3 = r3.startsWith(r4)
            r6.e = r3
            if (r3 != 0) goto L36
            java.io.File r3 = new java.io.File
            r3.<init>(r0)
            boolean r4 = r3.exists()
            if (r4 == 0) goto L12
            boolean r3 = r3.isFile()
            if (r3 != 0) goto L36
            goto L12
        L36:
            java.lang.String r2 = "invalid path: "
            r3 = -1008(0xfffffffffffffc10, float:NaN)
            java.lang.String r4 = "ArcGIS"
            if (r1 == 0) goto L98
            com.esri.core.internal.map.KmlLayerInternal r1 = r6.a     // Catch: java.lang.Exception -> L7b
            com.esri.core.io.UserCredentials r5 = r6.credentials     // Catch: java.lang.Exception -> L7b
            boolean r1 = r1.a(r0, r5)     // Catch: java.lang.Exception -> L7b
            if (r1 == 0) goto L61
            com.esri.core.internal.map.KmlLayerInternal r1 = r6.a     // Catch: java.lang.Exception -> L7b
            long r1 = r1.a()     // Catch: java.lang.Exception -> L7b
            r6.nativeHandle = r1     // Catch: java.lang.Exception -> L7b
            com.esri.core.geometry.Envelope r1 = r6.getFullExtent()     // Catch: java.lang.Exception -> L7b
            r6.setFullExtent(r1)     // Catch: java.lang.Exception -> L7b
            boolean r1 = r6.e     // Catch: java.lang.Exception -> L7b
            if (r1 != 0) goto Lb1
            com.esri.android.map.event.OnStatusChangedListener$STATUS r1 = com.esri.android.map.event.OnStatusChangedListener.STATUS.INITIALIZED     // Catch: java.lang.Exception -> L7b
            r6.changeStatus(r1)     // Catch: java.lang.Exception -> L7b
            goto Lb1
        L61:
            java.lang.StringBuilder r1 = new java.lang.StringBuilder     // Catch: java.lang.Exception -> L7b
            r1.<init>()     // Catch: java.lang.Exception -> L7b
            r1.append(r2)     // Catch: java.lang.Exception -> L7b
            r1.append(r0)     // Catch: java.lang.Exception -> L7b
            java.lang.String r1 = r1.toString()     // Catch: java.lang.Exception -> L7b
            android.util.Log.e(r4, r1)     // Catch: java.lang.Exception -> L7b
            com.esri.android.map.event.OnStatusChangedListener$STATUS r1 = com.esri.android.map.event.OnStatusChangedListener.STATUS.fromInt(r3)     // Catch: java.lang.Exception -> L7b
            r6.changeStatus(r1)     // Catch: java.lang.Exception -> L7b
            goto Lb1
        L7b:
            r1 = move-exception
            java.lang.StringBuilder r2 = new java.lang.StringBuilder
            r2.<init>()
            java.lang.String r5 = "url ="
            r2.append(r5)
            r2.append(r0)
            java.lang.String r0 = r2.toString()
            android.util.Log.e(r4, r0, r1)
            com.esri.android.map.event.OnStatusChangedListener$STATUS r0 = com.esri.android.map.event.OnStatusChangedListener.STATUS.fromInt(r3)
            r6.changeStatus(r0)
            goto Lb1
        L98:
            java.lang.StringBuilder r1 = new java.lang.StringBuilder
            r1.<init>()
            r1.append(r2)
            r1.append(r0)
            java.lang.String r0 = r1.toString()
            android.util.Log.e(r4, r0)
            com.esri.android.map.event.OnStatusChangedListener$STATUS r0 = com.esri.android.map.event.OnStatusChangedListener.STATUS.fromInt(r3)
            r6.changeStatus(r0)
        Lb1:
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: com.esri.android.map.ogc.kml.KmlLayer.initLayer():void");
    }

    @Override // com.esri.core.map.TimeAwareLayer
    public boolean isTimeAware() {
        KmlLayerInternal kmlLayerInternal = this.a;
        if (kmlLayerInternal != null) {
            return kmlLayerInternal.d();
        }
        return false;
    }

    @Override // com.esri.core.map.TimeAwareLayer
    public TimeExtent getTimeExtent() {
        KmlLayerInternal kmlLayerInternal = this.a;
        if (kmlLayerInternal != null) {
            try {
                return kmlLayerInternal.e();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
        return null;
    }

    @Override // com.esri.core.map.TimeAwareLayer
    public TimeExtent getTimeInterval() {
        return this.b;
    }

    @Override // com.esri.core.map.TimeAwareLayer
    public void setTimeInterval(TimeExtent timeExtent) {
        KmlLayerInternal kmlLayerInternal = this.a;
        if (kmlLayerInternal == null || timeExtent == null) {
            return;
        }
        this.b = timeExtent;
        kmlLayerInternal.a(timeExtent);
    }

    @Override // com.esri.core.map.TimeAwareLayer
    public TimeInfo getTimeInfo() {
        KmlLayerInternal kmlLayerInternal = this.a;
        if (kmlLayerInternal != null) {
            try {
                return kmlLayerInternal.i();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
        return null;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void a(String str, KmlNode kmlNode) {
        if (this.d != null) {
            if (Event.BEGIN_NODE_AUTO_REFRESH.toString().equalsIgnoreCase(str)) {
                this.d.onNodeBeginRefresh(kmlNode);
            } else if (Event.END_NODE_AUTO_REFRESH.toString().equalsIgnoreCase(str)) {
                this.d.onNodeEndRefresh(kmlNode);
            }
        }
    }

    protected void updateSpatialReferenceStatus(int i, Object obj) {
        if (!this.e) {
            super.updateSpatialReferenceStatus(i);
        } else if (i >= 0) {
            changeStatus(OnStatusChangedListener.STATUS.INITIALIZED);
            super.updateSpatialReferenceStatus(i);
        } else if (obj instanceof EsriSecurityException) {
            changeStatus(OnStatusChangedListener.STATUS.fromInt(((EsriSecurityException) obj).getCode()));
        } else {
            changeStatus(OnStatusChangedListener.STATUS.INITIALIZATION_FAILED);
        }
    }

    public void setKmlNodeEventListener(KmlNodeEventListener kmlNodeEventListener) {
        if (this.a != null) {
            this.d = kmlNodeEventListener;
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public class b implements KmlLayerInternal.SpatialReferenceCallback {
        b() {
        }

        @Override // com.esri.core.internal.map.KmlLayerInternal.SpatialReferenceCallback
        public void updateSpatialReferenceStatus(int i, Object obj) {
            KmlLayer.this.updateSpatialReferenceStatus(i, obj);
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public class a implements KmlLayerInternal.KmlNodeEventListener {
        a() {
        }

        @Override // com.esri.core.internal.map.KmlLayerInternal.KmlNodeEventListener
        public void onNodeRefresh(String str, KmlNode kmlNode) {
            KmlLayer.this.a(str, kmlNode);
        }
    }
}
